package com.jmx.demo2;

import javax.management.MBeanServer;

/**
 * AppAgent.. jdk 1.8版本 11未知
 *
 * @author Lizhong
 * @date 2019/4/24
 */
public class AppAgent {
    private MBeanServer mbs;

   /* public AppAgent() {
        // this.mbs = ManagementFactory.getPlatformMBeanServer();
        this.mbs = MBeanServerFactory.createMBeanServer("AppAgent");
        Producer hw = new Producer();
        ObjectName helloWorldName = null;
        try {
            helloWorldName = new ObjectName("AppAgent:name=Producer");
            // 此处将HelloWorld 绑定
            mbs.registerMBean(hw, helloWorldName);

            First handback = new First();
            mbs.registerMBean(handback, new ObjectName("AppAgent:name=First"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        startHtmlAdaptorServer();
    }

    public void startHtmlAdaptorServer() {
        HtmlAdaptorServer htmlAdaptorServer = new HtmlAdaptorServer();
        ObjectName adapterName = null;
        try { // 多个属性使用,分隔
            adapterName = new ObjectName("AppAgent:name=htmladapter,port=9092");
            htmlAdaptorServer.setPort(9092);
            // 将 HtmlAdaptorServer绑定
            mbs.registerMBean(htmlAdaptorServer, adapterName);
            htmlAdaptorServer.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String args[]) {
        System.out.println(" hello agent is running");
        AppAgent appAgent = new AppAgent();
    }*/
}



